package com.smommo.myapp.sleep;


public class WaitSleepCase {

    static final Object LOCK = new Object();

    public static void main(String[] args) throws InterruptedException {
//        sleeping();
        waiting();
    }

    private static void illegalWait() throws InterruptedException {
        LOCK.wait();
    }

    private static void waiting() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (LOCK) {
                try {
                    System.out.println("get(\"t\").debug(\"waiting...\");");
                    LOCK.wait(50000L);
                } catch (InterruptedException e) {
//                    get("t").debug("interrupted...");
                    e.printStackTrace();
                }
            }
        }, "t1");
        t1.start();
//        Thread.sleep(100);
        synchronized (LOCK) {

            System.out.println("     main.debug(\"other...\");");
        }

    }
    private static void sleeping() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (LOCK) {
                try {
                    System.out.println("   get(\"t\").debug(\"sleeping...\");");
                    Thread.sleep(5000L);
                } catch (InterruptedException e) {

                    System.out.println("   get(\"t\").debug(\"interrupted...\");");

                    e.printStackTrace();
                }
            }
        }, "t1");
        t1.start();

        Thread.sleep(100);
        synchronized (LOCK) {
            System.out.println("              main.debug(\"other...\");\n");

        }
    }
}